# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +---------------------------------------------------------------------
from common.utils.config import ConfigUtil
from apps.admin.schemas.apply.video import setting_schema as schema


class VideoSettingService:

    @classmethod
    async def detail(cls) -> schema.VideoSettingIO:
        """
        AI视频配置详情

        Returns:
            schema.VideoSettingIO

        Author:
            zero
        """
        luma = await ConfigUtil.get("video", "luma") or {}
        zhipu = await ConfigUtil.get("video", "zhipu") or {}
        return schema.VideoSettingIO(
            luma=schema.VideoConfig(
                status=int(luma.get("status", 0)),
                points=int(luma.get("points", 0)),
                channel=str(luma.get("channel", "")),
                model=str(luma.get("model", ""))
            ),
            zhipu=schema.VideoConfig(
                status=int(zhipu.get("status", 0)),
                points=int(zhipu.get("points", 0)),
                channel=str(zhipu.get("channel", "")),
                model=str(zhipu.get("model", ""))
            )
        )

    @classmethod
    async def save(cls, post: schema.VideoSettingIO) -> None:
        """
        AI视频配置保存

        Args:
            post (schema.VideoSettingIO): 配置参数

        Author:
            zero
        """
        await ConfigUtil.set("video", "luma", {
            "status": int(post.luma.status),
            "points": int(post.luma.points),
            "channel": str(post.luma.channel),
            "model": str(post.luma.model),
            "name": str(post.luma.name)
        })

        await ConfigUtil.set("video", "zhipu", {
            "status": int(post.zhipu.status),
            "points": int(post.zhipu.points),
            "channel": str(post.zhipu.channel),
            "model": str(post.zhipu.model),
            "name": str(post.zhipu.name)
        })
